<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">		<block slot="backText"></block>
			<block slot="content">邀请推广</block>
		</cu-custom>
		
		
		<image v-if="shareimg && shareimg" :src="shareimg" mode="widthFix" ></image>
		<!-- #ifdef APP-VUE -->
		<view class="shadow cu-rechange flex justify-center" style="width: 90%;height: auto;margin: 0 auto;">
			<view class="cu-btn line-orange round margin-right" @click="paste(member.share_url)">复制地址</view>
			<view class="cu-btn bg-orange round " @tap="bc_code">保存图片</view>
			<!-- <input type="text" style="background: #FE8B59;border: 1px solid #FF5202;color: #FF5202;" value="保存图片" class="hg-click hg-dsa" > -->
			<!-- <input type="text" value="复制地址" class="hg-click" readonly="readonly" disabled="disabled" @click="paste(member.share_url)"> -->
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shareimg:'',
				member:{
					
				}
			}
		},
		onLoad(options) {
			this.$common.getConfig().then((config) => {
				this.config = config
				
			})
			this.$common.getMember().then((member) => {
				this.member = member
				let share_url=this.config.web_url+"/h5/#/pages/member/index" + "?share_id=" + this.member.id;
				this.$jwx.readyShare(this.config.web_site_title,this.config.web_site_title,share_url,this.config.logo)
				this.showShare()
			})
			
		},
		
		methods: {
			showShare() {
				if (this.member.id > 0) {
					uni.showLoading({
						title: '加载中...',
					})
					this.$http.post('get_poster', {
						type: 'member',
						id: this.member.id,
						share_url: this.member.share_url,
						member_id: this.member.id,
						member_name: this.member.nickname,
						member_head: this.member.head_portrait,
						member_level: 0,
						reget: true
					}).then((res) => {
						this.shareimg = res.data.data
						uni.hideLoading();
					})
				}
			},
			paste(value) {
				uni.setClipboardData({
					data: value
				});
				this.$common.showError('复制成功')
			},
			bc_code(){
				
				uni.showLoading({
					title: '保存中...',
				})
				let that = this;
				//console.log('保存二维码')
				uni.downloadFile({           //获得二维码的临时地址
					url:this.shareimg,
					success:(res)=>{
						//console.log('获取url',res)
						if(res.statusCode == 200){
							uni.saveImageToPhotosAlbum({
								filePath:res.tempFilePath,//传入临时地址
								success: () => {
									this.$common.showError('保存成功')//封装的提示
								},
								fail : () => {
									this.$common.showError('保存失败')
								}
							})
							uni.hideLoading()
						}
					}
				})
			},
		}
	}
</script>

<style>
	.c_button{
		position: fixed;
		bottom: 16%;
		margin: 0 auto;
		width: 50%;
		text-align: center;
		background: #36C7FF;
		color: #fff;
		border-radius: 20px;
		height: 34px;
		font-size: 14px;
		line-height: 34px;
		margin-left: 24%;
	}
	uni-image{
		width: 100%;
	}
	uni-input{
		height: 2.5em;
		width: 30%;
	}
	.hg-url{
		background: #ffffff;
		border-radius: 20px;
		padding-left: 20px;
	}
	.hg-click{
		background: #45AEFF;
		border-radius:20px;
		text-align: center;
		color: #ffffff;
		margin: 0 auto;
	}
	
	.cu-rechange{
		position: fixed;
		bottom: 40px;
		left: 5%;
	}
</style>
